import Vue from 'vue'
import store from '../store';
import Router from 'vue-router'
import Home from '@/pages/Home'
import Index from '@/pages/Index'
import My from '@/pages/My'
import Music from '@/pages/Music'
import Top from '@/pages/Top'
import Search from '@/pages/Search'
import Login from '@/pages/Login'
import Detail from '@/pages/Detail'
import Music2 from '@/pages/Music/index2'
import Music3 from '@/pages/Music/index3'
import Comment from '@/pages/Comment/comment'

Vue.use(Router)

const router =  new Router({
  routes: [
    {
      path: '/',
      redirect:'/index'
    },
    {
      path: '/home',
      name: 'home',
      component: Home,
      children:[
        {
          path: '/index',
          name: 'index',
          component: Index
        },
        {
          path: '/my',
          name: 'my',
          component: My
        },
        {
          path: '/top',
          name: 'top',
          component: Top
        },
        {
          path: '/search',
          name: 'search',
          component: Search
        },
      ]
    },
    {
      path: '/music/:id/:name/:pic',
      name: 'music',
      props:true,
      component: Music
    },
    {
      path: '/music3',
      name: 'music3',
      props:true,
      component: Music3
    },
    {
      path: '/login',
      name: 'login',
      component: Login
    },{
      path: '/detail/:id',
      name: 'detail',
      component: Detail
    },
    {
      path: '/music2',
      name: 'music2',
      component: Music2
    },
    {
      path: '/comment/:id',
      name: 'comment',
      component: Comment
    },
    
  ]
})


router.beforeEach((to, from, next)=>{
  console.log(to.path);
  // if(to.path == '/reg'){
  //   return next();
  // }
   if(to.path == '/my' && store.getters.getUser == null){
     return next({path: '/login'})
   }
   next();
})

export default router;
